<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Model  {
	function login($user, $pass)
	{
		if (!empty($user) && !empty($pass))
		{
			$this->db->where('username', $user);
			$this->db->where('password', dohash($pass, 'md5'));
			$query = $this->db->get('user');
			if ($query && ($query->num_rows() > 0))
			{
				$row = $query->result();
				return $row[0]->UserID;
			} else {
				return 0;
			}
		} else {
			return 0;
		}
	}
	function getField($field)
	{
		$CI =& get_instance();
		$settings = $CI->sessionhelper->getSettings();
		if (isset($settings['user_id']))
		{
			$this->db->where('UserID',$settings['user_id']); 
											//I think we should do a lookup on the ID instead of passing it as a parameter!
											//- NA
											// Yeah lets do that
			$query = $this->db->get('user');
			if ($query && $query->num_rows() > 0)
			{
				$row = $query->result();
				return $row[0]->$field;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}
}

?>